package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class Intelligence extends Sprite
	{
		private var boat:Boat;
		public var goal:Point;
		
		public function Intelligence(boat:Boat, goal:Point)
		{
			this.boat = boat;
			this.goal = goal;
			addChild(boat);
		}
		
		public function move(e:Event):void {
			
			if(this.boat.imageBoat.x < this.goal.x - (this.boat.imageBoat.width/2) || this.boat.imageBoat.x > this.goal.x + (this.boat.imageBoat.width /2)){
				this.boat.isZPressed = true;
			} else {
				this.boat.isZPressed = false;
			}
			//var radians:Number = this.boat.imageBoat.rotation * Math.PI / 180;
			
			var adjacent:Number = this.goal.x - this.boat.imageBoat.x;
			var oppose:Number = this.goal.y - this.boat.imageBoat.y;
			var angle:Number = Math.atan(adjacent / oppose);
			
			this.boat.imageBoat.rotation = angle*180/Math.PI;
			
			trace(this.goal.x + ":" + this.goal.y + " " + this.boat.imageBoat.x + ":" + this.boat.imageBoat.y + " / " + Math.atan(adjacent / oppose));// + " cos:" + (Math.cos(angle) - Math.cos(radians)) + " sin : " + (Math.sin(angle) - Math.sin(radians))); 
			//trace("Radians :" + radians + "\tadjacent : " + adjacent + "\toppose : " + oppose + "\tangle : " + angle + "\tsinAngle : " + Math.sin(angle) + "\tcosAngle : " + Math.cos(angle) + "\tsinBoat : " + Math.sin(radians) + "\tcosBoat : " + Math.cos(radians));
			
			/*if(Math.cos(angle) < Math.cos(radians)){
				if(Math.sin(angle) < Math.sin(radians)){
					this.boat.isQPressed = true;
					this.boat.isDPressed = false;
				} else if(Math.sin(angle) > Math.sin(radians)){
					this.boat.isDPressed = true;
					this.boat.isQPressed = false;
				}
			} else if(Math.cos(angle) > Math.cos(radians)){
				if(Math.sin(angle) < Math.sin(radians)){
					this.boat.isQPressed = true;
					this.boat.isDPressed = false;
				} else if(Math.sin(angle) > Math.sin(radians)){
					this.boat.isDPressed = true;
					this.boat.isQPressed = false;
				}
			}
			else
			{
				this.boat.isDPressed = false;
				this.boat.isQPressed = false;
			}*/

			
			this.boat.move(e);
		}
	}
}